﻿using System;
using System.Threading;

public class Clock
{
    public event EventHandler Tick;
    public event EventHandler Alarm;

    public int AlarmTimeInSeconds { get; set; }

    public Clock(int alarmTimeInSeconds)
    {
        AlarmTimeInSeconds = alarmTimeInSeconds;
    }

    public void Run()
    {
        int currentTime = 0;

        while (true)
        {
            Thread.Sleep(1000);
            currentTime++;

            OnTick(currentTime);

            if (currentTime == AlarmTimeInSeconds)
            {
                OnAlarm();
            }
        }
    }

    protected virtual void OnTick(int currentTime)
    {
        Tick?.Invoke(this, new EventArgs());
        Console.WriteLine($"Tick: {currentTime} seconds elapsed.");
    }

    protected virtual void OnAlarm()
    {
        Alarm?.Invoke(this, new EventArgs());
        Console.WriteLine("Alarm: Ring! Ring! Ring!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        Clock clock = new Clock(10);

        clock.Tick += Clock_Tick;
        clock.Alarm += Clock_Alarm;

        clock.Run();
    }

    private static void Clock_Tick(object sender, EventArgs e)
    {
        Console.WriteLine("Clock is ticking...");
    }

    private static void Clock_Alarm(object sender, EventArgs e)
    {
        Console.WriteLine("Clock alarm is ringing!");
    }
}

